//
// Created by lugang on 2024/6/25.
//

#ifndef NET_SOCKET_H
#define NET_SOCKET_H
#include <assert.h>
#include <unistd.h>
#include <sys/socket.h>
#include <cstdio>
#include "SocketManager.h"

class Socket
{
private:
    int fd_{-1};
public:
    Socket()
    {
        assert(fd_ == -1);
        fd_ = socket(AF_INET,SOCK_STREAM,0);
        if(fd_ == -1)
        {
            printf("Create Socket Fd Error\n");
        }
    }

    ~Socket()
    {
        if(fd_)
        {
            ::close(fd_);
        }
    }

    Socket(const Socket& other) = delete;

    Socket& operator= (const Socket& other) = delete;

    Socket(Socket&& other)
    {
        fd_ = other.fd_;
        other.fd_ = -1;
    }

    auto GetFd() const ->int
    {
        return fd_;
    }

};


#endif //NET_SOCKET_H
